package solver;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Static class that represents a SAT problem. 
 * 
 * Contains variables and clauses.
 * 
 * TODO: please, check if this is really necessary.
 *
 */

@SuppressWarnings("serial")
public class SatProblem implements Serializable {
  
  public Map<String, String> featureVariables;
  public List<String> clauses;
  public SatProblem(Map<String, String> featureVariables,
      List<String> clauses) {
    super();
    this.featureVariables = featureVariables;
    this.clauses = clauses;
  }
  
  @Override
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("*** variables\n");
    sb.append(featureVariables);
    sb.append("\n");
    sb.append("*** constraints");
    for (String s : clauses) {
      sb.append("\n");
      sb.append(s);
    }
    return sb.toString();
  }
  
  public static SatProblem load(String fileName) throws IOException, ClassNotFoundException {
    FileInputStream fis = new FileInputStream(new File(fileName));
    ObjectInputStream ois = new ObjectInputStream(fis);
    SatProblem result = (SatProblem) ois.readObject();
    ois.close();
    fis.close();
    return result;
  }

}